<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<!--引入head的公共部分-->
<head th:replace="header::header-commo(登录)"></head>
<body>
<!--引入header的公共部分-->
<header th:replace="header::header-nav"></header>
<!--登录区域-->
<div class="container-fluid" style="height:460px;background:url('/img/loginbg.jpg') no-repeat;">
    <div class="row">
        <div class="col-md-7">
        </div>
        <div class="col-md-5">
            <div class="panel panel-default" style="width: 400px; margin-top: 50px;">
                <div class="panel-heading">
                    <h3 class="panel-title">用户登录</h3>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" th:action="@{/user/login}" method="post">
                        <div th:if="not ${#strings.isEmpty(error)}" class="alert alert-danger alert-dismissible"
                             role="alert">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <span th:text="${error}"></span>
                        </div>
                        <div class="form-group">
                            <label for="username" class="col-sm-3 control-label">用户名:</label>
                            <div class="col-sm-7" th:each="cookie:${#httpServletRequest.getCookies()}">
                                <input type="text" class="form-control" name="username" id="username"
                                       placeholder="请输入用户名"
                                       th:if="${cookie.getName().equals('cookieUserName')}"
                                       th:value="${cookie.getValue()}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-3 control-label">密码:</label>
                            <div class="col-sm-7" th:each="cookie:${#httpServletRequest.getCookies()}">
                                <input type="password" class="form-control" name="password" id="inputPassword3"
                                       placeholder="请输入密码"
                                       th:if="${cookie.getName().equals('cookieUserPassword')}"
                                       th:value="${cookie.getValue()}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputPassword4" class="col-sm-3 control-label">验证码:</label>
                            <div class="col-sm-5">
                                <input type="text" class="form-control" name="captcha" id="inputPassword4"
                                       placeholder="请输入验证码">
                            </div>
                            <div class="col-sm-4" style="padding: 0;">
                                <img id="showCode" height="34" th:src="@{/captcha}" src="img/code.png"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-10">
                                <div class="checkbox">
                                    <label class="checkbox-inline" >
                                        <div class="text-left" th:each="cookie:${#httpServletRequest.getCookies()}">
                                            <div th:if="${cookie.getName().equals('cookieUserPassword') and cookie.getValue()!=''}">
                                                <input type="checkbox" checked="checked" name="rememberUser" value="true"/>记住用户名和密码
                                                &nbsp;<a th:href="@{/register}">注册新用户</a>
                                            </div>
                                            <div th:if="${cookie.getName().equals('cookieUserPassword') and cookie.getValue().isEmpty()}">
                                                <input type="checkbox" name="rememberUser" value="true"/>记住用户名和密码
                                                &nbsp;<a th:href="@{/register}">注册新用户</a>
                                            </div>
                                        </div>
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-7">
                                <input class="btn btn-success  btn-block" type="submit" value="登录" name="submit"/>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!--底部-->
<footer th:replace="footer::footer"></footer>
</body>

<!-- 点击改变验证码 -->
<script th:inline="javascript">
    $(function () {
        var basePath = [[${#request.contextPath}]];
        $("#showCode").click(function () {
            //改变图片的src属性
            var d = new Date().getTime();
            $(this).attr("src", basePath + "/captcha?d=" + d);
        });
    });
</script>
</html>